package com.framework.common.config;

import com.framework.common.listener.IBaseEntityUpdate;
import com.framework.common.model.CommonUser;
import org.springframework.stereotype.Component;

import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.util.Date;

@Component
public class EntityUpdateListener {
    @PrePersist
    public void setCreatedOn(IBaseEntityUpdate create) {
        CommonUser userInfo = SessionUtil.getUser();
        create.setCreaterId(userInfo.getId());
        create.setCreateTime(new Date());
        create.setUpdaterId(userInfo.getId());
        create.setUpdateTime(new Date());
    }
    @PreUpdate
    public void setUpdatedOn(IBaseEntityUpdate update) {
        CommonUser userInfo = SessionUtil.getUser();
        update.setUpdaterId(userInfo.getId());
        update.setUpdateTime(new Date());
    }
}
